package org.xukai.core.aop.cglib;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author xukai
 * @desc
 * @date 2017-01-26-下午 10:56
 */
public class JDKProxy<T> implements InvocationHandler {

    private T t;

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("代理插入逻辑");
        method.invoke(t,args);
        return null;
    }


    public T newProxy(T targetObject) {
        this.t = targetObject;
        return (T)Proxy.newProxyInstance(targetObject.getClass().getClassLoader(), t.getClass().getInterfaces(), this);
        // 利用Proxy类取得代理对象
    }

}
